package com.example.spring.design.composite.lucency;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: orange
 * @create: 2023-08-19 23:54
 * @description:
 */
public abstract class AbstractComponent implements Sack, Commodity {
    private final List<Sack> chile = new ArrayList<>();

    @Override
    public void add(Sack sack) {
        if (sack == null) {
            throw new NullPointerException();
        }
        chile.add(sack);
    }

    @Override
    public double calc() {
        int all = 0;
        for (int i = 0; i < chile.size(); i++) {
            all += chile.get(i).calc();
        }
        return all;
    }
}
